package com.tanhua.api.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.db.BlackList;
import com.tanhua.db.UserInfo;
import com.tanhua.mapper.BlackListMapper;
import com.tanhua.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private BlackListMapper blackListMapper;

    public IPage findBlackList(Long userId, Integer pageNum, Integer pagesize) {

        // 1、开启分页功能
        Page page = new Page<UserInfo>(pageNum, pagesize);
        // 2、执行sql语句
        IPage<UserInfo> ipage= userInfoMapper.findBlackList(page, userId);
        return ipage;
    }

    @Override
    public void removeBlackList(Long userid, String blackid) {
        QueryWrapper<BlackList> qw = new QueryWrapper<>();
        qw.eq("black_user_id",blackid);
        qw.eq("user_id",userid);
        blackListMapper.delete(qw);
    }
}
